
{{template "base.html" .}}

{{define "content"}}
<script>
    $("#teacher-left-Booking").addClass("layui-this")//设置左侧导航栏
</script>
<!--操作按钮模板-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="accept">接受</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refuse">拒绝</a>
</script>
<!--操作按钮模板end-->
<div id="Booking-box">
    <div class="Booking-box-textRow layui-row layui-col-space20">
        <div  class="layui-col-md5 Booking-box-text">
            待处理
        </div>
        <div class="layui-col-md7 Booking-box-text">
            我的预约
        </div>
    </div>
    <div class="Booking-box-row layui-row layui-col-space20">
        <div id="Booking-box-left" class="layui-col-md5">
            <table id="bookingTable-1" lay-filter="demo"></table>
        </div>
        <div id="Booking-box-right" class="layui-col-md7">
            <table id="bookingTable-2"></table>
        </div>
    </div>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#bookingTable-1',
                url: 'http://127.0.0.1:8080/teacher/getBooking/'+getCookie("Id")+"/1", //数据接口,
                limit: 15,
                height: 'full-300',
                cols: [[
                    { field: 'Id', title: '编号', width: 88, sort: true, align: 'center',hide: true },
                    { field: 'StudentName', title: '学生',  align: 'center' },
                    { field: 'BookingTime', title: '预约时间',width: 160, align: 'center' },
                    {field: 'right', title: '操作',templet:'#barDemo', width: 130, align:'center'},
                ]],
            });
        });
    </script>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#bookingTable-2',
                url: 'http://127.0.0.1:8080/teacher/getBooking/'+getCookie("Id")+"/"+" ", //数据接口,
                limit: 15,
                height: 'full-300',
                cols: [[
                    { field: 'Id', title: '编号', width: 88, sort: true, align: 'center',hide: true },
                    { field: 'StudentName', title: '学生',  align: 'center' },
                    { field: 'Content', title: '内容', align: 'center' },
                    { field: 'StateName', title: '状态',  align: 'center' },
                    { field: 'BookingTime', title: '预约时间',width: 160, align: 'center' },
                ]],
            });
        });
    </script>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'refuse'){
                    layer.confirm('你确定要该预约拒绝吗', function(index){
                        $.ajax({
                            url:'/teacher/updateBooking/'+data.Id+"/4",
                            method:'post',
                            data:data.field,
                            dataType:'JSON',
                            success:function(res){
                                if(res.code=='1'){
                                    layer.msg(res.msg,{icon: res.code, time: 1000},function(){
                                        location.reload ()
                                    });
                                }
                                else{
                                    layer.msg(res.msg,{icon: res.code, time: 1000},function(){});
                                }
                            },
                        });
                    });
                } else if(obj.event === 'accept'){
                    $.ajax({
                        url:'/teacher/updateBooking/'+data.Id+"/2",
                        method:'post',
                        data:data.field,
                        dataType:'JSON',
                        success:function(res){
                            if(res.code=='1'){
                                layer.msg(res.msg,{icon: res.code, time: 1000},function(){
                                    location.reload ()
                                });
                            }
                            else{
                                layer.msg(res.msg,{icon: res.code, time: 1000},function(){});
                            }
                        },
                    });
                }
                // else if(obj.event === 'testRecord'){
                //     location.href="/teacher/stu_test/record/"+data.Id
                // }
            });
        })
    </script>
</div>
<style>
    #Booking-box{
        padding: 5%;
        height: 500px;
    }
    .Booking-box-row,#Booking-box-left,#Booking-box-right{
        height: 100%;
    }
    #Booking-box-left{

    }
    #Booking-box-right{

    }
</style>
{{end}}
